
package com.xiaoma.myaudience.biz.adapter;

import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xiaoma.myaudience.R;
import com.xiaoma.myaudience.biz.activity.ActivitysDetailActivity;
import com.xiaoma.myaudience.biz.activity.HomeActivity;
import com.xiaoma.myaudience.biz.activity.ReviewActivity;
import com.xiaoma.myaudience.biz.model.ActivityDetailInfoModel;
import com.xiaoma.myaudience.biz.model.HomeInfoModel;
import com.xiaoma.myaudience.biz.view.LoadingImageView;
import com.xiaoma.myaudience.util.PicUtils;
import com.xiaoma.myaudience.util.model.ModelUtils;

/**
 * 活动详细页面的Adapter
 * @author jpren
 *
 */
public class ActivitysDetailAdapter extends BaseAdapter {
    private List<Map<String, Object>> mList;	
    private Context mContext;
    private LayoutInflater mInflater;
    private String mSizeStr;
    private String mEventid;
    public ActivitysDetailAdapter(Context context, List<Map<String, Object>> list,String eventid) {
        mList = list;
        mContext = context;
        mEventid = eventid;
        mInflater = LayoutInflater.from(mContext);
        mSizeStr = PicUtils.composeSize((int) context.getResources().getDimension(
                R.dimen.list_item_img_width), (int) context.getResources().getDimension(
                R.dimen.list_item_img_height));
    }

    @Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.activity_event_pics_item, null);
			ViewHolder holder = new ViewHolder();
			holder.img = (LoadingImageView) convertView.findViewById(R.id.img);
			holder.username = (TextView) convertView.findViewById(R.id.username);
			holder.datetime = (TextView) convertView.findViewById(R.id.datetime);
            convertView.setTag(holder);

		}
		ViewHolder holder = (ViewHolder) convertView.getTag();
		final Map<String, Object> item = (Map<String, Object>) getItem(position);
		holder.img.setLoadingDrawable(ModelUtils.getStringValue(item, ActivityDetailInfoModel.PARAM_PATH), mSizeStr);
		holder.username.setText("来源：" + ModelUtils.getStringValue(item, ActivityDetailInfoModel.PARAM_USERNAME));
		holder.datetime.setText("时间：" + ModelUtils.getStringValue(item, ActivityDetailInfoModel.PARAM_DATETIME));
		
		holder.img.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext, ReviewActivity.class);
	    		//intent.putExtra("eventid", mEventid);
	    		intent.putExtra(HomeInfoModel.PARAM_PICID, ModelUtils.getStringValue(item, HomeInfoModel.PARAM_PICID));
    			intent.putExtra(HomeInfoModel.PARAM_TYPE, "1");
    			intent.putExtra("from", "ActivityDetail");
	    		mContext.startActivity(intent);
			}
		});
		
		return convertView;
	}

	private class ViewHolder {
        LoadingImageView img;
        TextView username;
        TextView datetime;
    }

}